<template>
  <!--ASN/收货单-->
  <div id="Asndetails">
    <g-details :detailData="inputData" :inputConfig="inputConfig" :rules="rules" @pop="setdata" ref="input">
    </g-details>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";

export default {
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object,
    },
  },
  name: "asnDetails",
  data() {
    return {
      rules: {
        receiptkey: [
          { required: true, message: this.$inputPlease('in.asn'), trigger: "blur" },
        ],
        storerkey: [
          { required: true, validator: this.storerkey, trigger: "change" },
        ],
        type: [{ required: true, message: "请选择类型", trigger: "blur" }],
        /*grossweight: [
                    {validator: this.verify, trigger: 'blur'},
                ],*/
        // totalvolume: [
        //     { validator: this.verify, trigger: 'blur' },
        // ],
        overageoveridepercent: [{ validator: this.verify, trigger: "blur" }],
      },
    };
  },
  computed: {
    inputConfig() {
      if (this.$route.query.newFlag) {
        return [
          {
            type: "input",
            label: this.$t('in.asn'),
            disabled: true,
            props: "receiptkey",
          },
          {
            type: "select",
            label: this.$t('config.asnType'),
            disabled: false,
            props: "type",
            options: this.getOptions("codelkup/RECEIPTYPE"),
          },
          {
            type: "select",
            label: this.$t('in.asnStatus'),
            disabled: true,
            props: "status",
            options: this.getOptions("codelkup/RECSTATUS"),
          },
          {
            type: "date",
            label: this.$t('config.asnDate'),
            disabled: true,
            props: "adddate",
          },
          {
            type: "table",
            label: this.$t('config.shipper'),
            disabled: false,
            props: "storerkey",
            tableConfig: [
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input",
              },
              { label: this.$t('config.company'), prop: "company", input: "input" },
              {
                label: this.$t('config.city'),
                prop: "city",
                input: "input",
              },
              { label: this.$t('config.provice'), prop: "state", input: "input" },
              {
                label: this.$t('config.postcode'),
                prop: "zip",
                input: "input",
              },
            ],
            url: `queryStorer/1/?/${this.$store.state.wms}`,
            filterKey: "storerkey",
            break: true
          },
          {
            type: "input",
            label: this.$t('in.totalqtyexpected'),
            disabled: true,
            props: "totalqtyexpected",
          },
          {
            type: "input",
            label: this.$t('in.totalqtyreceived'),
            disabled: true,
            props: "totalqtyreceived",
          },
          {
            type: "input",
            label: this.$t('in.grossweight'),
            disabled: false,
            props: "grossweight",
          },
          {
            type: "input",
            label: this.$t('in.totalvolume'),
            disabled: false,
            props: "totalvolume",
          },
          {
            type: "input",
            label: this.$t('in.pokey'),
            disabled: false,
            props: "pokey",
          },
          // {
          //   type: "select",
          //   label: "运输状态",
          //   disabled: false,
          //   props: "transportationstatus",
          //   options: this.getOptions("codelkup/APPSTATUS"),
          // },
          {
            type: "date",
            label: this.$t('in.receiptdate'),
            disabled: false,
            props: "receiptdate",
          },
          {
            type: "input",
            label: this.$t('in.closeddate'),
            disabled: true,
            props: "closeddate",
            break: true
          },
          // {
          //   type: "date",
          //   label: this.$t('home.expcteddate'),
          //   disabled: false,
          //   props: "expectedreceiptdate",
          // },
          // {
          //   type: "date",
          //   label: this.$t('out.actualshipdate'),
          //   disabled: false,
          //   props: "actualshipdate",
          // },
          // {
          //   type: "date",
          //   label: this.$t('out.scheduledshipdate'),
          //   disabled: false,
          //   props: "scheduledshipdate",
          // },
          {
            type: "input",
            label: this.$t('in.sourcelocation'),
            disabled: true,
            props: "sourcelocation",
          },
          {
            type: "input",
            label: this.$t('in.overageoveridepercent'),
            disabled: false,
            props: "overageoveridepercent",
          },
          {
            type: "table",
            label: this.$t('in.rtxpofromhourse'),
            props: "rtxpofromhourse",
            tableConfig: [
              {
                label: this.$t('common.code'),
                prop: "code",
                input: "input",
              },
              {
                label: this.$t('common.desc'),
                prop: "description",
                input: "input",
              },
            ],
            url: `/queryshipstore/undefined/?/${this.$store.state.wms}`,
            filterKey: "code",
            break: true
          },
          // {
          //   type: "input",
          //   label: this.$t('out.referencetype'),
          //   disabled: true,
          //   props: "referencetype",
          // },
          // {
          //   type: "input",
          //   label: this.$t('out.referencedocument'),
          //   disabled: true,
          //   props: "referencedocument",
          // },
          // {
          //   type: "input",
          //   label: this.$t('out.referencelocation'),
          //   disabled: true,
          //   props: "referencelocation",
          // },
          {
            type: "textarea",
            label: this.$t('app.remark'),
            disabled: this.$route.query.newFlag,
            props: "notes",
          },
          // {
          //   type: "date",
          //   label: "Actual Arrval Date",
          //   disabled: false,
          //   props: "arrivaldatetime",
          // },
          // {
          //   type: "date",
          //   label: "Actual Dearture Date",
          //   disabled: false,
          //   props: "actualdeparturedate",
          // },
          // {
          //   type: "date",
          //   label: "已核实的结算日期",
          //   disabled: true,
          //   props: "verifiedcloseddate",
          // },

        ];
      } else {
        return [
          {
            type: "input",
            label: this.$t('in.asn'),
            disabled: true,
            props: "receiptkey",
          },
          {
            type: "select",
            label: this.$t('config.asnType'),
            disabled: false,
            props: "type",
            options: this.getOptions("codelkup/RECEIPTYPE"),
          },
          {
            type: "select",
            label: this.$t('in.asnStatus'),
            disabled: true,
            props: "status",
            options: this.getOptions("codelkup/RECSTATUS"),
          },
          {
            type: "date",
            label: this.$t('config.asnDate'),
            disabled: true,
            props: "adddate",
          },
          {
            type: "table",
            label: this.$t('config.shipper'),
            disabled: false,
            props: "storerkey",
            tableConfig: [
              {
                label: this.$t('config.shipper'),
                prop: "storerkey",
                input: "input",
              },
              { label: this.$t('config.company'), prop: "company", input: "input" },
              {
                label: this.$t('config.city'),
                prop: "city",
                input: "input",
              },
              { label: this.$t('config.provice'), prop: "state", input: "input" },
              {
                label: this.$t('config.postcode'),
                prop: "zip",
                input: "input",
              },
            ],
            url: `queryStorer/1/?/${this.$store.state.wms}`,
            filterKey: "storerkey",
            break: true
          },
          {
            type: "input",
            label: this.$t('in.totalqtyexpected'),
            disabled: true,
            props: "totalqtyexpected",
          },
          {
            type: "input",
            label: this.$t('in.totalqtyreceived'),
            disabled: true,
            props: "totalqtyreceived",
          },
          {
            type: "input",
            label: this.$t('in.grossweight'),
            disabled: false,
            props: "grossweight",
          },
          {
            type: "input",
            label: this.$t('in.totalvolume'),
            disabled: false,
            props: "totalvolume",
          },
          {
            type: "input",
            label: this.$t('in.pokey'),
            disabled: false,
            props: "pokey",
          },
          // {
          //   type: "select",
          //   label: "运输状态",
          //   disabled: false,
          //   props: "transportationstatus",
          //   options: this.getOptions("codelkup/APPSTATUS"),
          // },
          {
            type: "input",
            label: this.$t('in.closeddate'),
            disabled: true,
            props: "closeddate",
            break: true
          },
          {
            type: "date",
            label: this.$t('in.receiptdate'),
            disabled: false,
            props: "receiptdate",
          },
          // {
          //   type: "date",
          //   label: this.$t('home.expcteddate'),
          //   disabled: false,
          //   props: "expectedreceiptdate",
          // },
          // {
          //   type: "date",
          //   label: this.$t('out.actualshipdate'),
          //   disabled: false,
          //   props: "actualshipdate",
          // },
          // {
          //   type: "date",
          //   label: this.$t('out.scheduledshipdate'),
          //   disabled: false,
          //   props: "scheduledshipdate",
          // },
          // {
          //   type: "date",
          //   label: this.$t('app.createDate'),
          //   disabled: true,
          //   props: "adddate",
          // },

          {
            type: "input",
            label: this.$t('in.sourcelocation'),
            disabled: true,
            props: "sourcelocation",
          },
          {
            type: "input",
            label: this.$t('in.overageoveridepercent'),
            disabled: false,
            props: "overageoveridepercent",
          },
          {
            type: "table",
            label: this.$t('in.rtxpofromhourse'),
            props: "rtxpofromhourse",
            tableConfig: [
              {
                label: this.$t('common.code'),
                prop: "code",
                input: "input",
              },
              {
                label: this.$t('common.desc'),
                prop: "description",
                input: "input",
              },
            ],
            url: `/queryshipstore/undefined/?/${this.$store.state.wms}`,
            filterKey: "code",
          },
          {
            type: "select",
            label: this.$t('in.receiptfinishflag'),
            props: "receiptfinishflag",
            options: [
              { code: "P", description: "P" },
              { code: "PS", description: "PS" },
              { code: "PF", description: "PF" },
              { code: "S", description: "S" },
            ],
            break: true
          },
          {
            type: "textarea",
            label: this.$t('app.remark'),
            disabled: this.$route.query.newFlag,
            props: "notes",
          },
          // {
          //   type: "date",
          //   label: "Actual Arrval Date",
          //   disabled: false,
          //   props: "arrivaldatetime",
          // },
          // {
          //   type: "date",
          //   label: "Actual Dearture Date",
          //   disabled: false,
          //   props: "actualdeparturedate",
          // },
          // {
          //   type: "date",
          //   label: "已核实的结算日期",
          //   disabled: true,
          //   props: "verifiedcloseddate",
          // },


        ];
      }
    },
  },
  methods: {
    verify(rule, value, callback) {
      if (value === "") {
        callback(new Error());
      } else {
        var re = /[^0-9.]/;
        let te = value;
        let flag = re.test(te);
        if (!flag) {
          if (value < 0) {
            this.$message.error(this.$t('app.inputNumberPlease'));
            this.inputData[rule.field] = "";
            callback(new Error());
          } else {
            callback();
          }
        } else {
          this.$message.error(this.$t('app.inputNumberPlease'));
          this.inputData[rule.field] = "";
          callback(new Error());
        }
      }
    },
    storerkey(rule, value, callback) {
      if (!value) {
        callback(new Error());
      } else {
        this.$api
          .get(`/isExists/${1}/${value}/${this.$store.state.wms}`)
          .then((res) => {
            
              if (parseInt(res.bean) <= 0) {
                this.$message.error(`不存在的货主:${value}`);
                this.inputData[rule.field] = "";
                callback(new Error());
              } else {
                callback();
              }
          })
          .catch((e) => {
            callback(new Error());
            this.$message.error(e);
          });
      }
    },
    setdata(data, close, listId) {
      if (listId == 'storerkey') {
        this.inputData.storerkey = data.storerkey;
      } else if (listId == 'rtxpofromhourse') {
        this.inputData.rtxpofromhourse = data.code;
      }
      close(false);
    },
  },
  mounted() { },
  watch: {
    "inputData.storerkey"(data) {
      this.inputConfig.forEach((item) => {
        if (item.props == "rtxpofromhourse") {
          item.url = `/queryshipstore/${data}/?/${this.$store.state.wms}`;
        }
      });
    },
  },
};
</script>

<style scoped>

</style>
